# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
head=ListNode(1)
head.next=ListNode(2)
head.next.next=ListNode(3)
head.next.next.next=ListNode(4)
head.next.next.next.next=ListNode(5)

def reverseList(head: ListNode) -> ListNode:
    if head==None:
        return None
    #使用头插法来实现链表反转
    #创建一个工作头结点
    headnew=ListNode()
    headPro=head
    while headPro:
        headNext=headPro.next
        headPro.next=headnew.next
        headnew.next=headPro
        headPro=headNext

    while headnew:
        print(headnew.val)
        headnew=headnew.next
reverseList(head)